//
// Created by wlk12 on 2024/8/7.
//
#include "iostream"

int main()
{
    {
        std::cout << "-------------------Base Class Array ------------------------" << std::endl;
        class B{
        public:
            virtual ~B() = default;
            int n1 = 1;

            virtual B* clone() { return this; }

            virtual B& operator+(const B& b2)
            {
                return *this;
            }
        };
        class B2{
        public:
            virtual ~B2() {}
            int n2 = 2;
        };
        class D final : public B, public B2
        {
        public:
            ~D() override
            {
                std::cout<< "~D" << std::endl;
            }
            int m = 4;
            D* clone() override { return this; }

            B& operator+(const B& b2) override
            {
                return *this;
            }
        };

        auto da = new D[5];
        B2* pb = da;
        std::cout << "pb[1].n2:" << pb[1].n2 << std::endl; // 输出错误
        delete[] pb; // msvc 可正常工作


        std::cout << "------------------- typeid -----------------------" << std::endl;
        auto d2 = new D;
        B* pb2 = d2;

        D d3;
        B& bfd = d3; // typeid(有虚函数的类型)，会使用RTTI(Runtime Type Identify)，获取运行时类型

        std::cout << "Point, typeid(d2) == typeid(D*): " << (typeid(d2) == typeid(D*)) << std::endl;
        std::cout << "Point, typeid(pb2) == typeid(D*): " << (typeid(pb2) == typeid(D*)) << std::endl;

        std::cout << "Reference, typeid(d3) == typeid(D): " << (typeid(d3) == typeid(D)) << std::endl;
        std::cout << "Reference, typeid(bfd) == typeid(D): " << (typeid(bfd) == typeid(D)) << std::endl;


        class BB
        {
        public:
            //            virtual ~BB() = default;
            int bb = 0;
        };
        class DD : public  BB
        {
        public:
            int dd = 0;

        };

        DD d4;
        BB& bbfdd = d4; // typeid(没有虚函数的类型)，是编译时确定的类型

        auto& ddf = static_cast<DD&>(bbfdd);

        std::cout << "no virtual Reference, typeid(d4) == typeid(DD): " << (typeid(d4) == typeid(DD)) << std::endl;
        std::cout << "no virtual Reference, typeid(bbfdd) == typeid(DD): " << (typeid(bbfdd) == typeid(DD)) << std::endl;

    }

    {
        class B
        {
        public:
            B() = default;
            B(int n) : n(n){}
            int n = 0;
        };
        class C
        {
        public:
            C() = default;
            C(const B& b) : n(b.n) {}
            int n = 1;
        };

        B b = 10;
        C c = b;
//        C c2 = 12; // compile error
        C c3 = C(13);
        C c4 = static_cast<C>(14);
    }

    {
        // target_compile_options(type PUBLIC $<$<CXX_COMPILER_ID:MSVC>: /Zc:char8_t- >) 关闭了使用 u8string
        std::string u8str = u8"abcde";
        std::cout << u8str << std::endl;
    }
    return 0;
}